<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title></title>
  <script src="../vue.js"></script>
</head>
<body>
  <div id="root">
    {{age}} {{doubleAge}} {{trippleAge}}
    <button v-on:click="handleClick">click</button>
  </div>
  <script type="module">
    Vue.config.productionTip = false

    var vm = new Vue({
      el: '#root',
      data: {
        age: 18,
        trippleAge: 0
      },

      computed: {
        doubleAge() {
          // setTimeout(() => {
          //   console.log(0)
          //   return this.age * 2
          // }, 2000)
          return this.age * 2
        }
      },

      watch: {
        age: {
          immediate: true,
          handler(newValue, oldValue) {
            setTimeout(() => {
              this.trippleAge = newValue * 3
            }, 2000)
          }
        }
      },

      methods: {
        handleClick() {
          this.age = 19
        }
      },
    })
  </script>
</body>
</html>